/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.city.set.eia.cityblog.entities.managedbeans;

import edu.city.set.eia.cityblog.entities.Comment;
import edu.city.set.eia.cityblog.sessionbeans.CommentFacadeLocal;
import java.util.List;
import java.util.ResourceBundle;
import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author Breath
 */

@ManagedBean
@RequestScoped
public class CommentBean {

    private static final ResourceBundle citypress = ResourceBundle.getBundle("citypress");
   
    List<Comment> comments;
    Comment comment = new Comment();
    @EJB CommentFacadeLocal commentFac;

    @PostConstruct
    public void retrieveComments(){
        this.setCustomers(commentFac.findAll());
    }

    public List<Comment> getCustomers() {
        return comments;
    }

    public void setCustomers(List<Comment> list) {
        this.comments = list;
    }
    
    public Comment getComment() {
        return comment;
    }

    public void setComment(Comment comment) {
        this.comment= comment;
    }

    public void persistComment() {
        
       comment = commentFac.find(1); 
        if (comment != null){
            commentFac.edit(comment);
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_INFO,
                    citypress.getString("update.message"), citypress.getString("update.message")));
        }
    }        
}
